package org.yufan.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.yufan.exception.CustomException;
import org.yufan.result.Result;
import org.yufan.result.ResultUtils;
import org.yufan.service.SMSService;

/**
 * Created by zxd on 2018/4/2.
 */
@Controller
@RequestMapping("/sms")
public class SMSController {

    private Logger LOGGER= LoggerFactory.getLogger(SMSController.class);

    @Autowired
    private SMSService smsService;


    @RequestMapping("/{phone}/{type}")
    @ResponseBody
    public Result  sendSms(@PathVariable("phone")String phone,@PathVariable("type")Integer type) throws CustomException {
        LOGGER.info("发送短信的电话为{}，类型为{}",phone,type);
        if(smsService.sendSms(phone,type)){
            return ResultUtils.buildSuccess("短信发送成功!");
        }else{
            return ResultUtils.buildFail(105,"短信发送失败!");
        }
    }




}
